package com.wildish.utils;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

public class LogUtil {
	private Logger loggerDebug = null;
	private Logger loggerError = null;
	private String o_message = null;

	private LogUtil(String objMessage) {
		this.o_message = objMessage;
	}

	public static LogUtil getLogUtil(Object message) {
		String objMessage = message.toString();
		return new LogUtil(objMessage);
	}

	public void debug(Object message) {
		if (loggerDebug == null) {
			loggerDebug = Logger.getLogger("debugfile");
			loggerDebug.setLevel(Level.DEBUG);
		}
		if (this.o_message == null)
			return;
		System.out.println("[" + o_message + "] - " + message);
		loggerDebug.debug("[" + o_message + "] - " + message);
	}

	public void error(Object message) {
		if (loggerError == null) {
			loggerError = Logger.getLogger("errorfile");
			loggerError.setLevel(Level.ERROR);
		}
		if (this.o_message == null)
			return;
		loggerError.error("[" + o_message + "] - " + message);
	}

	public void error(String message, Exception ex) {
		if (loggerError == null) {
			loggerError = Logger.getLogger("errorfile");
			loggerError.setLevel(Level.ERROR);
		}
		if (this.o_message == null)
			return;
		loggerError.error("[" + o_message + "] - " + message, ex);

	}
}
